package com.cblue.qimokao.controller;

import com.alibaba.fastjson.JSONObject;
import com.cblue.qimokao.entity.Film;
import com.cblue.qimokao.entity.Order;
import com.cblue.qimokao.service.OrderService;
import com.cblue.qimokao.vo.Result;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Resource
    private OrderService orderService;

    @RequestMapping("/add")
    public Result add(@RequestBody Film doctor, HttpServletRequest request){
        Order order = new Order();
        order.setDoctorid(doctor.getId());
        order.setFee(50);
        String username = (String)request.getSession().getAttribute("username");
        order.setUname(username);
        orderService.add(order);

        Map<String,Object> result = new HashMap();
        result.put("orderId",order.getId());
        result.put("dept",doctor.getDept());
        result.put("dname",doctor.getDname());
        result.put("worktime",doctor.getWorktime());
        result.put("fee",order.getFee());
        result.put("uname",username);

        return new Result(0, JSONObject.toJSONString(result));
    }


}
